<template>
  <el-form size="mini" :inline="true">
    <el-form-item v-if="school"><edu-search-school :value.sync="form.mhm_id" :args="{}" :form-datas="{}" /></el-form-item>
    <el-form-item><edu-date :value.sync="form.date" :options="dateOptions" :args="dateArgs" /></el-form-item>
  </el-form>
</template>

<script>
import EduSearchSchool from '@/pages/school/choose';
import EduDate from '@public/form/date.vue';
import { shortcutsLayterThreeMonth } from '@/common/js/const.js';

export default {
  components: {
    EduSearchSchool,
    EduDate
  },
  props: {
    school: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      form: {
        mhm_id: '',
        date: ['', '']
      },
      dateArgs: {
        date_type: 'daterange',
        format: 'yyyy-MM-dd'
      },
      dateOptions: {
        disabledDate: function(time) {
          // 计算两年前的今天时间
          const date = new Date();
          date.setFullYear(date.getFullYear() - 2);
          date.setDate(date.getDate() - 1);

          return time.getTime() > Date.now() || time.getTime() < date.getTime();
        },
        shortcuts: shortcutsLayterThreeMonth
      }
    };
  },
  watch: {
    'form.date': {
      handler(date) {
        this.$emit('update:date', date);
      }
    },
    'form.mhm_id': {
      handler(school) {
        this.$emit('update:school', school);
      }
    }
  }
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 0;
}
</style>
